#!/usr/bin/perl
# Version 0.2.1

$testcase = "old_lsa";

# 1 = PASS
# 2 = FAIL
# 3 = INCONCLUSIVE
$verdict = 3;

$dumpfile = "$testcase.dump";
$logfile = "$testcase.log";

if ($#ARGV ne 1) {
        print("Usage: $testcase.pl dump_file log_file");
        exit 1;
}

$dumpfile = $ARGV[0];
$logfile = $ARGV[1];

#------------------------------------------------------------------------------

$state = 0;

# Open the dumpfile
$success = 1;
open(DUMPFILE, $dumpfile) or $success = 0;

if ($success eq 1) {
		
	while(<DUMPFILE>) {
		if($state eq 0) {
			if(/0\.0\.0\.2 > (.*) OSPFv2-ls_upd (.*) S 8ffffffe/) {
				# found the update with the old lsa
				$state = 1;
			}
		}
		if(($state eq 1)or($state eq 2)) {
			if(/0\.0\.0\.1 > (.*) OSPFv2-ls_upd (.*) S 70000001/){
				# found the update with the newer instance - very well
				if($state eq 1) {
					# so far - so good...
					$state = 2;
				} else {
					# bad - this must be a retransmission which shouldn't occur
					$state = 3;
				}
			}
		}
		
	}
	
	close(DUMPFILE);
	
	if($state eq 2) {
		$verdict = 1;
	} else {
		$verdict = 2;
	}
}

if($verdict eq 1) {
	print("RUT correctly handles an old LSA. Test PASSED.\n");
} elsif($verdict eq 2) {
	if($state eq 0) {
		print("Tester doesn't behave as it should. No relevant results found. Test FAILED.\n");
	} elsif($state eq 1) {
		print("RUT doesn't flood the newer LSA instance. Test FAILED.\n");
	}  elsif($state eq 3) {
		print("RUT mustn't retransmit the new LSA instance. Test FAILED.\n");
	} 
	
} else {
	print("Cannot evaluate test results. Test INCONCLUSIVE.\n");
}

#------------------------------------------------------------------------------
print("### VERDICT for $testcase: ");

if ($verdict eq 1) { 
        print("PASS"); 
} elsif ($verdict eq 2) {
        print("FAIL");
} else {
        print("INCONCLUSIVE");
}

print(" ###\n");